<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.js"></script>

    <input type="button" id="a" value="重新开始"></br>
    <span>请输入要猜的数字:</span>
    <input type="text" id="text">
    <input type="button" id="guess" value="提交"></br>
    <span id="d">已经猜的次数：</span><span id="count">0</span><br/>
    <span >结果：</span><span id="e"></span>
    <script>
        let count = 0;
         let randomNumber = Math.floor(Math.random() * 100 + 1);
            console.log(randomNumber);
        $("#guess").click(function () {
            count++;
            $("#count").text(count);

            let getNumber = $("#text");
            if (getNumber.val() > randomNumber) {
                $("#e").text("你猜的数字大了");
                $("#e").css("color", "red");
            } else if (getNumber.val() < randomNumber) {
                $("#e").text("你猜的数字小了");
                $("#e").css("color", "red");
            } else {
                $("#e").text("恭喜你，猜对了");
                $("#e").css("color", "green");
            }
        })
        $("#a").click(function () {
            count = 0;
            randomNumber = Math.floor(Math.random() * 100 + 1);
            console.log(randomNumber);
            $("#count").text(0);
            $("#e").text("");
            $("#text").val("")
        })
    </script>
</body>

</html>